package com.foreknow.controller;

import com.foreknow.model.Guestbook;
import com.foreknow.service.impl.GuestbookServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

public class FindServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 因为第一次客户端向服务器端发送的请求为Post，所以首先要调用doPost方法
            doGet(req,resp);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=utf-8");
        GuestbookServiceImpl guestbookService = new GuestbookServiceImpl();
        List<Guestbook> list = guestbookService.getQueryAll();
        //将list集合在服务器端保存（后期就可以在页面中获取到list集合）
        req.setAttribute("list",list);
        // 将资源转发到list.jsp
        req.getRequestDispatcher("/list.jsp").forward(req,resp);
    }
}
